﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KerriganDataContract;
using System.ServiceModel;
using KerriganDataContract.Evaluation;

namespace KerriganService.DAC
{
    public class CustomerEvaluationDAC
    {

        public static Boolean AddMark(int idSession, int idCustomer, CustomerEvaluationDC evaluation)
        {
            Boolean result = false;

            try
            {
                using (KerriganDBEntities db = new KerriganDBEntities())
                {
                    TSessionApplicant entity = new TSessionApplicant();
                    entity = db.TSessionApplicants.FirstOrDefault(f => f.IdApplicantFK == idCustomer && f.IdSessionFK == idSession);
                    entity.TCustomerEvaluation = CopyBoToEntity(evaluation);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }

            return result;
        }


        public static CustomerEvaluationDC CopyEntityToBo(TCustomerEvaluation entity)
        {
            CustomerEvaluationDC bo = new CustomerEvaluationDC();

            try
            {
                bo.Id = entity.IdCustomerEvaluation;
                bo.Date = entity.EvaluationDate;
                bo.Mark = entity.InstructorMark;
                bo.Comment = entity.InstructorComment;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }

            return bo;
        }

        public static TCustomerEvaluation CopyBoToEntity(CustomerEvaluationDC bo)
        {
            TCustomerEvaluation entity = new TCustomerEvaluation();

            try
            {
                entity.IdCustomerEvaluation = bo.Id;
                entity.EvaluationDate = bo.Date;
                entity.InstructorMark = bo.Mark;
                entity.InstructorComment = bo.Comment;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }

            return entity;
        }
    }
}